// Legal Notices:
//    Copyright (C) 2011, GuruCE.
//    http://guruce.com
//    ALL RIGHTS RESERVED
//
//    This file, software, or program is supplied under the terms of a
//    license agreement and/or nondisclosure agreement with GuruCE
//    and may not be copied or disclosed except in accordance with the 
//    terms of that agreement.  This file, software, or program contains 
//    copyrighted material and/or trade secret information of 
//    GuruCE, and must be treated as such. GuruCE reserves all rights in
//    this material, except as the license agreement or nondisclosure 
//    agreement specifically indicate.
//
//    All rights reserved.  No part of this program or publication may be
//    reproduced, transmitted, transcribed, stored in a retrieval system
//    retrieval system, or translated into any language or computer
//    language, in any form or by any means, electronic, mechanical,
//    magnetic, optical, chemical, manual, or otherwise, without the prior
//    written permission of GuruCE.
//
// Disclaimer:
//    GuruCE makes no warranty of any kind regarding this code.  This code
//    is provided on an "AS-IS" basis and GuruCE will not provide any 
//    support assistance, installation, training or other services.
//    GuruCE does not provide any updates, enhancements or extensions. 
//    GuruCE specifically disclaims any warranty of merchantability, 
//    non-infringement, fitness for any particular purpose, or any other 
//    warranty.
//
//    GuruCE disclaims all liability, including liability for infringement
//    of any proprietary rights, relating to use of the code. No license, 
//    express or implied, by estoppel or otherwise, to any intellectual 
//    property rights is granted herein.
//
//    GuruCE has no responsibility under warranty, indemnification or 
//    otherwise, for the modification or customization of any GuruCE
//    software by GuruCE, customer, website user or any third party even
//    if such customization and/or modification is done using GuruCE
//    tools, training or methods documented by GuruCE.
//
#pragma once

//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
#define CAN_INSTANCES       2

#define CAN_WRITE           TRUE
#define CAN_READ            FALSE

#define CAN_EXTENDED        TRUE
#define CAN_STANDARD        FALSE

#define CAN_REMOTE          TRUE
#define CAN_DATA            FALSE

#define CAN_TXONREMOTERX    TRUE
#define CAN_TXNOW           FALSE

//------------------------------------------------------------------------------
// Structures
//------------------------------------------------------------------------------
typedef struct
{
    BOOL    bExtended;      // Frame format is standard (CAN_STANDARD) or extended (CAN_EXTENDED) 
    UINT32  ui32ID;         // Message ID. If using standard format ID the ID is 11 bits, if using the extended format the ID is 29 bits
    UINT16  ui16Timestamp;  // Receives the transmission timestamp (captured when the frame first appeared on the bus)
    BYTE    btDataLen;      // Number of valid bytes in btData
    BYTE    btData[8];      // Message data, max 8 bytes
} CAN_FRAME, *PCAN_FRAME;

typedef struct
{
    BYTE    btIndex;        // CAN Bus Message Buffer Index to use for this transmission. Set to 0xFF to let driver find a free message buffer
    BOOL    bWrite;         // This transmission is read (CAN_READ) or write (CAN_WRITE)
    BOOL    bRemote;        // Request remote frame (CAN_REMOTE) or send data (CAN_DATA)
    CAN_FRAME canFrame;     // The actual frame data. See CAN_FRAME for a description of the CAN_FRAME items
    BOOL    bTxOnRemoteRx;  // CAN_TXNOW to send immediately, CAN_TXONREMOTERX to send when a frame with the same ID is received. Only valid when (CAN_WRITE && CAN_DATA)
    BYTE    btPriority;     // The transmission priority (0 = highest priority, 7 = lowest priority)
    UINT32  ui32IDMask;     // Bitmask for CAN_READ ID: 0; don't care, 1; the corresponding bit in the ID is checked against the one received
    DWORD   dwTimeout;      // Maximum time this transmission can take in ms
    DWORD   dwError;        // Receives the result of the action on this packet (ERROR_SUCCESS == All ok)
} CAN_PACKET, *PCAN_PACKET;

// CAN Transfer Block
typedef struct
{
    PCAN_PACKET pCANPackets;
    DWORD       dwNumPackets;
} CAN_TRANSFER_BLOCK, *PCAN_TRANSFER_BLOCK;